home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Idle / Postponer.cp < prev    next >
Text File  |  1997-06-28  |  982b  |  70 lines

  1. // Postponer.cp
  2.  
  3. #ifndef Postponer_h
  4. #include "Postponer.h"
  5. #endif
  6. #ifndef Method_h
  7. #include "Method.h"
  8. #endif
  9.  
  10. Postponer::Postponer( const Method& theMethod )
  11.   : link( this ),
  12.      perform( theMethod )
  13.   {
  14.     TheList();
  15.   }
  16.  
  17. Postponer::~Postponer()
  18.   {
  19.   }
  20.  
  21. ListOf< Postponer >& Postponer::TheList()
  22.   {
  23.     static ListOf< Postponer > list;
  24.     return list;
  25.   }
  26.  
  27. void Postponer::Schedule()
  28.   {
  29.     Assert( !Pending() );
  30.     TheList().Add( link, afterEnd );
  31.   }
  32.  
  33. void Postponer::Cancel()
  34.   {
  35.     Assert( Pending() );
  36.     TheList().Remove( link );
  37.   }
  38.  
  39. void Postponer::Flush()
  40.   {
  41.     if ( Pending() )
  42.       {
  43.         Cancel();
  44.         this->perform();
  45.       }
  46.   }
  47.  
  48. void Postponer::Execute( Tick stop )
  49.   {
  50.     ListOf< Postponer >& list( TheList() );
  51.     
  52.     while ( !list.IsEmpty() )
  53.       {
  54.         Postponer *p = list.First()->Target();
  55.         list.Remove( p->link );
  56.         p->perform();
  57.         
  58.         if ( Tick::Now() >= stop )
  59.             break;
  60.       }
  61.   }
  62.  
  63. bool Postponer::CanSleep()
  64.   {
  65.     return TheList().IsEmpty();
  66.   }
  67.  
  68. #include "ListLink.cp"
  69. #include "ListOf.cp"
  70.